<script language="javascript" type="text/javascript">
    $(window).scroll(
    function()
    {
        scrollTop = $(window).scrollTop();
        docHeight = getDocHeight();
        winHeight = getWinHeight();
        scrolltop20 = Math.round((getDocHeight() - getWinHeight())*0.9);
        result = getDocHeight() - getWinHeight();
		
        console.log('Top Scroll: '+ scrollTop +' || Win Height: '+ winHeight +' || Doc Height: '+ docHeight+' || scrolltop20: '+scrolltop20+' || result :'+ result );
	
        if($(window).scrollTop() >= scrolltop20)
        {
            if(killScroll == false) 
            {
                killScroll = true;
				
                $('#loading').show();
                $('#loadding-text').show();			
                $('#loading').html('<img src="images/loading.gif" alt="" width="150" height="13" />');

                if($("li:last").data('ctype') == 'clubListDetail')
                {
                    clubListDetail('clubListDetail', $("li:last").data('clubid')); 
                }
                setTimeout(function(){killScroll = false},500);	
            }
        }
    }
);

    function searchClub()
    {
        //alert('word : '+$('#product_search').val()+' -> '+'product_status : '+$('#product_status').val()+' category : '+$('#category').val()+'trade : '+ $('#trade').val()+'province : '+$('#province').val() );
	
        if($('#club_search').val() != '')
        {	
            $('#fromSearchClub').submit();
        }
        else
        {
            $('#clubAlert').popup('open');
            setTimeout(function(){$('#clubAlert').popup('close'); $('#club_search').focus()},1000);
        }
    }

</script> 
<!-- Start of news page -->
<div data-role="page" id="club">
    <div data-role="header"> 
        <h1>พูดคุยประสาชาวคลับ</h1>
        <a rel="external" id="link_web" href="?q=club" data-icon="back" data-iconpos="right" >กลับ</a>        
    </div><!-- /header -->

    <div data-role="content">
        <?php
        $club = $db->select_query('SELECT name FROM clubs WHERE id = ' . $db->antihack($_GET['cId']) . ' LIMIT 1');
        $getNameClub = $db->fetch($club);
        ?>	
        <div id="clubListDetails">
            <ul data-role="listview">
                <li data-role="list-divider" id="listDivider_step">
                    <a rel="external" href="?q=home">หน้าแรก</a>&nbsp;&nbsp;>>&nbsp;&nbsp;<a rel="external" href="?q=club">ชมรม</a>&nbsp;&nbsp;>>&nbsp;&nbsp;<a rel="external" href="?q=clubListDetail&&cId=<?php echo $_GET['cId']; ?>"><?php echo $getNameClub['name']; ?></a>
                </li>    
                <?php
                $res = $db->select_query('SELECT * FROM clubs_post WHERE club_id = ' . $db->antihack($_GET['cId']) . ' ORDER BY post_id DESC LIMIT 20');
                $countList = $db->rows($res);
                if($countList != 0)
                {
                    while($post = $db->fetch($res))
                    {
                        $countReply = $db->num_rows('clubs_reply', 'reply_id', 'post_id = ' . $post['post_id'] . '');
                        ?>
                        <li data-ctype="clubListDetail" data-clubid="<?php echo $_GET['cId']; ?>" id="clubList_<?php echo $post['post_id']; ?>" last_id="<?php echo $post['post_id']; ?>" >
                            <a rel="external" href="?q=clubDetail&cId=<?php echo $post['club_id']; ?>&postId=<?php echo $post['post_id']; ?>">
                                <img src="images/icon_clubListDetail.gif" />
                                <h2><?php echo $post['post_title']; ?></h2>
                                <p><?php echo 'โดบ : ' . $post['cr_by'] . ' วันที่ : ' . $post['cr_date']; ?></p>
                                <span class="ui-li-count ui-btn-up-c ui-btn-corner-all"><?php echo $countReply; ?></span>
                            </a>
                        </li>
                        <?php
                    }
                }
                else
                {
                    ?>
                    <li>
                        <h3>--  ไม่พบข้อมูลในระบบ --</h3>
                    </li>
                    <?php
                }
                ?>
            </ul> 
        </div>
        <?php
        if($countList != 0)
        {
            ?>
            <div id="loadding-text" style="clear:both;">&nbsp;&nbsp;</div>
            <div id="loading" align="center"><img src="images/loading.gif" alt="" width="150" height="13" /></div>
            <?php
        }
        ?>        
    </div><!-- /content -->
    <div data-role="footer" >
        <h4>Version 1.0 Beta</h4>
        <a id="link_web" href="http://www.mocyc.com" data-icon="refresh" data-iconpos="right" class="ui-btn-right">แบบปกติ</a>
    </div><!-- /footer -->
</div><!-- /page -->